<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" isELIgnored="false"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<title>角色列表</title>
	<link type="text/css" rel="stylesheet" href="${pageContext.request.contextPath }/css/zTreeStyle/zTreeStyle.css" />
	<script type="text/javascript" src="${pageContext.request.contextPath }/js/zTree/jquery.ztree.core-3.5.min.js"></script>
	<script type="text/javascript" src="${pageContext.request.contextPath }/js/zTree/jquery.ztree.excheck-3.5.min.js"></script>
	<script type="text/javascript">
	<!--
	var setting = {
		async:{
			enable:true
			,type:"post"
			,url:"${pageContext.request.contextPath }/sysuser/getSysMenuInfoTreeData.do"
			,dataFilter:function(treeId, parentNode, responseData) {
				if(true == responseData.isSuccess){
					return responseData.returnObject;
				}else{
					return {"menuId":"0","menuName":"获取失败"};
				}
			}
		},view: {
			dblClickExpand: false
		}
		,check: {
			enable: true
		}
		,data:{
			key:{
				name:"menuName"
			}
			,simpleData:{
				enable:true
				,idKey:"menuId"
				,pIdKey:"parentId"
			}
		}
	};

	function delUserGroup(groupId,groupName){
		$("#tmpl_modal").tmpl({"modelId":"delUserGroupModal","modelTitle":"角色操作","modelContent":"删除角色:"+groupName}).appendTo(document.body);
		$("#delUserGroupModal").modal();
		$("#delUserGroupModal .modal-footer :button:first").on("click",function(){
			$.post("${pageContext.request.contextPath}/sysuser/deleteSysUserGroup.do",{"groupId":groupId},function(data){
				$("#delUserGroupModal").modal("hide");
				window.document.href = "${pageContext.request.contextPath}/sysuser/querySysUserGroupPage.do";
			},"json");
		});
	}
	
	var zTree;
	$(function(){
		$(".sysMenu").on("click",function(){
			var groupId = $(this).parents("tr:first").find("td:first-child :hidden").val();
			setting.async.otherParam = {"groupId":groupId};
			//zTree.reAsyncChildNodes(null, "refresh");
			$.fn.zTree.init($("#menuTree"), setting);
			$("#formMenu :hidden[name='groupId']").val(groupId);
			$("#myRoleMenu").modal();
		});
		
		$("#btn_sub").on("click",function(){
			var nodes = zTree.getCheckedNodes(true);
			var menuIds = new Array();
			$.each(nodes,function(i,n){
				menuIds.push(n.menuId);
			});
			$("#formMenu").ajaxSubmit({
				url:"${pageContext.request.contextPath}/sysuser/saveSysGroupMenuInfo.do"
				,type:"post"
				,dataType:"json"
				,data:{"menuIds":menuIds.join()}
				,success:function(data){
					$("#myRoleMenu").modal("hide");
					if(true == data.isSuccess){
						$("#tmpl_alert").tmpl({type:"success", title:"成功",message:data.returnObject}).appendTo("#message_alert");
					}else{
						$("#tmpl_alert").tmpl({type:"error",title:"失败",message:data.errorMsg}).appendTo("#message_alert");
					}
				}
			});
		});
		
		$.fn.zTree.init($("#menuTree"), setting);
		zTree = $.fn.zTree.getZTreeObj("menuTree");
		
	});

	//-->
	</script>
</head>
<body>
	<div class="container-fluid">
    <hr>
    <div class="row-fluid">
      <div class="span12"><a href="${pageContext.request.contextPath }/sysuser/createSysUserGroup.do" class="btn btn-primary">新增</a></div>
    </div>
    <div class="row-fluid">
      <div class="span12">
      	<div class="widget-box">
          <div class="widget-title"> <span class="icon"><i class="icon-th"></i></span>
            <h5>角色列表</h5>
          </div>
          <div class="widget-content nopadding">
            <table class="table table-bordered data-table">
              <thead>
                <tr>
                  <th>角色名</th>
                  <th>描述</th>
                  <th>操作</th>
                </tr>
              </thead>
              <tbody>
              	<c:forEach items="${pageInfo.list }" var="sysUserGroup">
                <tr class="gradeA">
                  <td><input type="hidden" value="${sysUserGroup.groupId }" />${sysUserGroup.groupName }</td>
                  <td>${sysUserGroup.groupMeno }</td>
                  <td>
                  	<div class="btn-group"><a href="${pageContext.request.contextPath }/sysuser/getSysUserGroup.do?groupId=${sysUserGroup.groupId }" class="btn btn-mini">修改</a>
                  	<c:if test="${sysUserGroup.aliveFlag ne flagProtect  }">
                  	<a href="javascript: delUserGroup('${sysUserGroup.groupId }','${sysUserGroup.groupName }');" class="btn btn-mini">删除</a>
                  	</c:if>
                  	<a class="btn btn-mini sysMenu">权限</a>
                  	<a href="${pageContext.request.contextPath }/sysuser/querySysUserByGroup.do?groupId=${sysUserGroup.groupId }" class="btn btn-mini">负责人</a>
                  	</div>
                  </td>
                </tr>
              	</c:forEach>
              </tbody>
            </table>
          </div>
        </div>
      </div>
    </div>
    </div>
    <div id="myRoleMenu" class="modal hide">
      <div class="modal-header">
        <button data-dismiss="modal" class="close" type="button">×</button>
        <h3>设置角色权限</h3>
      </div>
      <div class="modal-body">
      <form id="formMenu" action="">
      	<input type="hidden" name="groupId" />
      	<ul id="menuTree" class="ztree"></ul>
      </form>
      </div>
      <div class="modal-footer"> <button id="btn_sub" type="button" class="btn btn-primary">确定</button> <a data-dismiss="modal" class="btn" href="#">取消</a> </div>
    </div>
</body>
</html>